/*
 * Copyright (C),2015,北京新诺创科软件技术有限公司
 * author zhangmengliang
 */
package com.xnck.example.jertest.util;


import com.xnck.example.jertest.context.HttpContext;

import javax.servlet.http.HttpSession;

/**
 * Http Session常用工具类
 */
public class SessionUtil {
	/**
     * 设置session的值
     */
    public static void setAttr(String key, Object value) {
        HttpSession session = HttpContext.get().getRequest().getSession(true);
        session.setAttribute(key, value);
    }

    /**
     * 获取session的值
     */
    public static Object getAttr(String key) {
        HttpSession session = HttpContext.get().getSession();
        if (null != session){
            return session.getAttribute(key);
        }
        return null;
    }

    /**
     * 删除Session值
     */
    public static void removeAttr(String key) {
        HttpSession session = HttpContext.get().getSession();
        if (null != session){
            session.removeAttribute(key);
        }
    }
}
